﻿

using System;
using System.Data;
using Model;
namespace Dal
{
	public class BaoMing3Dal
	{
		public BaoMing3Dal()
		{
		}
 		#region Insert
 		public static int Insert(BaoMing3 baoMing3)
		{	
			string sql = @"Insert Into BaoMing3 (
					OrderNO,
					ActivityID,
					ActivityName,
					ActivityOrg,
					ActivityDate,
					LimitNums,
					BabyClass,
					BabyName,
					ParentName,
					Mobile,
					Notes,
					Status,
					Checkinfos,
					UserId,
					AddTime
				) values('{0}',{1},'{2}','{3}','{4}',{5},'{6}','{7}','{8}','{9}','{10}',{11},'{12}',{13},'{14}')";
			sql = string.Format(sql,
					SqlHelper.String(baoMing3.OrderNO),
					baoMing3.ActivityID,
					SqlHelper.String(baoMing3.ActivityName),
					SqlHelper.String(baoMing3.ActivityOrg),
					baoMing3.ActivityDate,
					baoMing3.LimitNums,
					SqlHelper.String(baoMing3.BabyClass),
					SqlHelper.String(baoMing3.BabyName),
					SqlHelper.String(baoMing3.ParentName),
					SqlHelper.String(baoMing3.Mobile),
					baoMing3.Notes,
					baoMing3.Status,
					SqlHelper.String(baoMing3.Checkinfos),
					baoMing3.UserId,
					baoMing3.AddTime
				);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
		
		#region Update
 		public static int Update(BaoMing3 baoMing3)
		{	
			string sql = @"Update BaoMing3 set 

					OrderNO= '{0}',
					ActivityID= {1},
					ActivityName= '{2}',
					ActivityOrg= '{3}',
					ActivityDate= '{4}',
					LimitNums= {5},
					BabyClass= '{6}',
					BabyName= '{7}',
					ParentName= '{8}',
					Mobile= '{9}',
					Notes= '{10}',
					Status= {11},
					Checkinfos= '{12}',
					UserId= {13},
					AddTime= '{14}'
				where

					Id= {15}";
			sql = string.Format(sql,
					SqlHelper.String(baoMing3.OrderNO),
					baoMing3.ActivityID,
					SqlHelper.String(baoMing3.ActivityName),
					SqlHelper.String(baoMing3.ActivityOrg),
					baoMing3.ActivityDate,
					baoMing3.LimitNums,
					SqlHelper.String(baoMing3.BabyClass),
					SqlHelper.String(baoMing3.BabyName),
					SqlHelper.String(baoMing3.ParentName),
					SqlHelper.String(baoMing3.Mobile),
					baoMing3.Notes,
					baoMing3.Status,
					SqlHelper.String(baoMing3.Checkinfos),
					baoMing3.UserId,
					baoMing3.AddTime,
					baoMing3.Id);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
 
 

 		#region Delete
 		public static int Delete(Int32 id)
		{
		
			string sql = @"Delete from BaoMing3 where 
					Id= {0}";
			sql = string.Format(sql,
					id
);
			return SqlHelper.ExecSql(sql);
		} 
		#endregion
 
 		#region Select
 		
 		public static DataSet Select()
		{
			string sql = "select a.* from BaoMing3 a "; 
			return SqlHelper.Select(sql);
		}
				
		public static BaoMing3 Select(Int32 id)
		{
			BaoMing3 baoMing3 = null;
			string sql = @"select a.* from BaoMing3 a  where
					a.Id= {0}
";
			sql = string.Format(sql,
					id
);
			DataSet ds = SqlHelper.Select(sql);
			if(SqlHelper.HasRow(ds))
				baoMing3 = new BaoMing3(ds.Tables[0].Rows[0]);					
			return baoMing3;
		}
		
		public static DataSet Select(string where)
		{ 
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from BaoMing3 a  where 1=1 " + where ;
			return SqlHelper.Select(sql);
		}
		
		public static DataSet SelectForList(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;
						
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from BaoMing3 a where 1=1 " + where;
                
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}		
		public static DataSet Select(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;			
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;			
			string sql = "select a.* from BaoMing3 a  where 1=1 " + where;
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}
		#endregion
	}
}
